<template>
  <div class="page">
    <div class="layui-fluid">
      <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
          <div class="layui-card">

            <div class="layui-card-body">
              <div class="layui-form" lay-filter="">

                <div class="layui-form-item">
                  <div class="layui-inline">
                    <label class="layui-form-label">分组名称</label>
                    <div class="layui-input-inline" style="width: 180px;">
                      <input type="text" name="groupName" placeholder="请输入分组名称" v-model="itemData.groupName"
                        autocomplete="off" class="layui-input a" maxlength="10">
                    </div>
                  </div>
                </div>
                <div class="layui-form-item">
                  <label class="layui-form-label">状态</label>
                  <div class="layui-input-block" style="width:180px">
                    <select name="activeStatus" lay-filter="activeStatus" v-model="activeStatus">
                      <option value="ENABLE">启用</option>
                      <option value="DISABLE">禁用</option>
                    </select>
                  </div>
                </div>

                <div class="layui-form-item">
                  <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo"
                      @click="confirmOk">确认</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <input type="hidden" id='id' />
  </div>
</template>
<script>

export default {
  name: 'wucgoodsfzadd',
  data () {
    return {
      id: '',
      shopId: '',
      itemData: {},
      activeStatus: 'ENABLE',
    }
  },
  mounted () {
    var _this = this;
    layui.use('upload', function () {
      var upload = layui.upload;
      var uploadInst = upload.render({
        elem: '#layuiadmin-upload-useradmin',//绑定元素
        data: {
          type: 3
        }
        , url: imguploadurl //上传接口
        , done: function (res) {
          layer.msg('上传成功');
          _this.itemData.image = res.msg;
        }
        , error: function () {
          layer.msg('上传失败');
        }
      });
    });
    window.getdates = this.getdates;

  },
  methods: {
    getdates: function (data) {
      var _this = this;
      _this.id = data.id;
      _this.shopId = data.shopId;
      var url = "/mallcredit/bapi/v1.9/item-group/itemGroup/" + data.shopId + "/" + data.id;
      ajaxRequest(url, 'GET', 'json', '', function (ret, err) {
        _this.itemData = ret.data;
        _this.activeStatus = ret.data.activeStatus;
      })
    },
    confirmOk: function () {
      var _this = this;
      var len = $(".a").length;
      for (var i = 0; i < len; i++) {
        if ($(".a").eq(i).val() == '' || $(".a").eq(i).val() <= 0) {
          var msg = $(".a").eq(i).attr("placeholder");
          layer.msg('请输入正确的' + msg);
          return;
        }
      }
      var url = '/mallcredit/bapi/v1.9/item-group';
      if (_this.id) {
        var hat = 'PUT';
        var dates = {
          groupName: _this.itemData.groupName,
          shopId: _this.shopId,
          activeStatus: _this.activeStatus,
          icon: '',
          id: _this.itemData.id,
        }
      } else {
        var hat = 'POST';
        var dates = {
          groupName: _this.itemData.groupName,
          shopId: _this.shopId,
          activeStatus: _this.activeStatus,
          icon: '',
        }
      }
      ajaxRequest(url, hat, 'json', dates, function (ret, err) {
        //alert(JSON.stringify(ret))
        layer.msg("操作成功");
        setTimeout(function () {
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);
          parent.location.reload();
        }, 1000)
      })
    }
  },
  updated: function () {
    var _this = this;
    layui.use('form', function () {
      var form = layui.form;
      form.render();
      form.on('select(activeStatus)', function (data) {
        _this.activeStatus = data.value;
      });
    });

  },
}
</script>
<style scoped>
</style>
